package com.HQCourse.vod.vod.service.impl;


import com.HQCourse.result.Result;
import com.HQCourse.vod.vod.mapper.TeacherMapper;
import com.HQCourse.vod.vod.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.HQCourse.model.vod.Teacher;
import com.example.HQCourse.vo.vod.TeacherQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author zww
 * @since 2023-06-17
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Autowired
    private TeacherService teacherService;

    @Override
    public IPage<Teacher> iPage(int current, int limit, TeacherQueryVo teacherQueryVo) {
        Page<Teacher> teacherpage = new Page<>(current, limit);
        if (teacherQueryVo == null) {
            IPage<Teacher> iPage = teacherService.page(teacherpage, null);
            return iPage;
        } else {
            String name = teacherQueryVo.getName();
            Integer level = teacherQueryVo.getLevel();
            String joinDateBegin = teacherQueryVo.getJoinDateBegin();
            String joinDateEnd = teacherQueryVo.getJoinDateEnd();
            QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
            if (!StringUtils.isEmpty(name)) {
                wrapper.like("name", name);
            }
            if (!StringUtils.isEmpty(level)) {
                wrapper.eq("level", level);
            }
            if (!StringUtils.isEmpty(joinDateBegin)) {
                wrapper.ge("join_data", joinDateBegin);
            }
            if (!StringUtils.isEmpty(joinDateEnd)) {
                wrapper.le("join_data", joinDateEnd);
            }
            //调用方法分页查询

            IPage<Teacher> iPage = teacherService.page(teacherpage, wrapper);
            return iPage;

        }
    }
}